package com.fb.fbvedioplayer.CustomView;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.fb.fbvedioplayer.R;

import java.util.HashMap;
import java.util.LinkedHashMap;

import cn.jzvd.JZVideoPlayerStandard;

/**
 * 这里可以监听到视频播放的生命周期和播放状态
 * 这个播放控件自带有分享按钮7
 * Created by fb on 2017/7/2.
 */
public class FBVideoPlayerStandardShareButton extends JZVideoPlayerStandard {

    //分享按钮
    public ImageView shareButton;

    public FBVideoPlayerStandardShareButton(Context context) {
        super(context);
    }

    public FBVideoPlayerStandardShareButton(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void init(Context context) {
        super.init(context);
        shareButton = findViewById(R.id.share);
        shareButton.setOnClickListener(this);
    }

    @Override
    public void setUp(Object[] dataSourceObjects, int defaultUrlMapIndex, int screen, Object... objects) {
        super.setUp(dataSourceObjects, defaultUrlMapIndex, screen, objects);
        if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
            shareButton.setVisibility(View.VISIBLE);
        } else {
            shareButton.setVisibility(View.INVISIBLE);
        }
    }

    /**
     * 设置视频播放所需参数
     * @param lowUrl 低视频地址
     * @param normalUrl 中视频地址
     * @param highUrl 高视频地址
     * @param title 视频名称
     * @param screen 屏幕类型
     */
    public void setVideo(String lowUrl,String normalUrl,String highUrl,String title,int screen){
        //将各种清晰度的版本
        LinkedHashMap map = new LinkedHashMap();
        map.put("高清", highUrl);
        map.put("标清", normalUrl);
        map.put("普清", lowUrl);
        Object[] objects = new Object[3];
        objects[0] = map;
        objects[1] = false;//looping
        objects[2] = new HashMap<>();
        ((HashMap) objects[2]).put("key", "value");//header
        setUp(objects, 2
            , screen, title);
    }
    /**
     * 设置视频播放所需参数
     * @param normalUrl
     * @param title
     * @param screen 屏幕类型
     */
    public void setVideo(String normalUrl,String title,int screen){
            setUp(normalUrl,screen,title);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        int i = v.getId();
        if (v.getId() == R.id.share) {//点击分享按钮触发
            //视频暂停
            goOnPlayOnPause();

            AlertDialog.Builder builder = new AlertDialog.Builder(getContext(), 3);
            builder.setIcon(R.mipmap.ic_launcher);
            builder.setTitle("普通对话框");
            builder.setMessage("测试弹出框对视频播放是否有影响");
            builder.create().show();
            Toast.makeText(getContext(), "你点击了分享按钮", Toast.LENGTH_SHORT).show();
        }

        if (i == cn.jzvd.R.id.fullscreen) {
            if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
                //click quit fullscreen
            } else {
                //click goto fullscreen
            }
        }
    }

    @Override
    public int getLayoutId() {
        return R.layout.my_layout_standard_share;
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return super.onTouch(v, event);
    }

    @Override
    public void startVideo() {
        super.startVideo();
    }

    @Override
    public void onStateNormal() {
        super.onStateNormal();
    }

    @Override
    public void onStatePreparing() {
        super.onStatePreparing();
    }

    @Override
    public void onStatePlaying() {
        super.onStatePlaying();
    }

    @Override
    public void onStatePause() {
        super.onStatePause();
    }

    @Override
    public void onStateError() {
        super.onStateError();
    }

    @Override
    public void onStateAutoComplete() {
        super.onStateAutoComplete();
    }

    @Override
    public void onInfo(int what, int extra) {
        super.onInfo(what, extra);
    }

    @Override
    public void onError(int what, int extra) {
        super.onError(what, extra);
    }

    @Override
    public void startWindowFullscreen() {
        super.startWindowFullscreen();
    }

    @Override
    public void startWindowTiny() {
        super.startWindowTiny();
    }

}
